package fmi.chesstern.ui;

import javax.swing.JFrame;

import fmi.chesstern.controller.GameCommandExecutor;
import fmi.chesstern.game.GameState;
import fmi.chesstern.ui.gui.ChessBoard;
import fmi.chesstern.ui.gui.ChessBoardFrame;
import fmi.chesstern.ui.gui.FieldClickEvent;
import fmi.chesstern.ui.gui.FieldClickListener;
import fmi.chesstern.ui.gui.GUIBoardState;
import fmi.chesstern.ui.gui.GUIController;

public class GUI implements GameUI {
	@Override
	public void start(GameCommandExecutor commandExecutor, GameState state) {
		GUIBoardState guiState = new GUIBoardState(state);
		ChessBoard board = new ChessBoard(guiState);
		final GUIController controller = new GUIController(commandExecutor, guiState);
		
		board.addFieldClickListener(new FieldClickListener() {
			@Override
			public void handleEvent(FieldClickEvent event) {
				controller.click(event.getField());
			}
		});
		
		JFrame game = new ChessBoardFrame(board, controller, guiState);
		game.setSize(600, 700);
		game.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		game.setVisible(true);
	}
	
	@Override
	public void exit() {
		System.exit(0);
	}
}
